/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import { Upload } from 'antd';
import React from 'react';
import type { UploadProps } from 'antd/es/upload/interface';
import { CryptoParams, crypto } from '@base/utils/encryption';

interface UploadWithCryptoProps {
  options?: CryptoParams['options'];
}

const UploadWithCrypto: React.FC<UploadWithCryptoProps & UploadProps> = (props) => {
  const { action, options, ...restProps } = props;
  const actionPromise = typeof action === 'string' ? () => crypto({ url: action, options }) : '';

  return (
    <Upload action={actionPromise} {...restProps}>
      {props.children}
    </Upload>
  );
};

export default UploadWithCrypto;
